package com.xiaotu.util;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.stereotype.Component;

import java.io.*;
import java.util.Properties;

/**
 * @author zhangxiao
 * @create 2022-05-10 14:10
 */
@Component
public class PropertiesUtil {

    public Properties getProperties(String propertiesName) {
        Properties pps = new Properties();
        InputStream stream = getClass()
                .getClassLoader()
                .getResourceAsStream(propertiesName);
        BufferedReader br = null;
        InputStreamReader in = null;
        try {
            in = new InputStreamReader(stream, "UTF-8");
            br = new BufferedReader(in);
            pps.load(br);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ObjectUtil.isNotNull(in)) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (ObjectUtil.isNotNull(br)) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return pps;
    }

}
